﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNet.ActivatorCreateInstanceDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var engine = new Engine();

            var parts = new[]
            {
                new Part(),
                new Part()
            };

            var car = (Car)Activator.CreateInstance(typeof(Car), new object[] {engine, parts});
            Console.WriteLine(car.Parts.Count());
        }
    }

    public class Car
    {
        public IEngine Engine { get; set; }
        public IEnumerable<IPart> Parts { get; set; }

        public Car(IEngine engine, IEnumerable<IPart> parts)
        {
            Engine = engine;
            Parts = parts;
        }
    }

    public interface IEngine {}
    class Engine : IEngine {}

    public interface IPart {}
    class Part : IPart {}
}
